home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / glass / glass.lha / GLASS / glammar / gg10.c < prev    next >
C/C++ Source or Header  |  1991-01-21  |  35KB  |  1,213 lines

  1. /*
  2.  
  3.     This file is a part of the GLAMMAR source distribution 
  4.     and therefore subjected to the copy notice below. 
  5.     
  6.     Copyright (C) 1989,1990  Eric Voss, ericv@cs.kun.nl 
  7.  
  8.     This program is free software; you can redistribute it and/or modify
  9.     it under the terms of the GNU General Public License as published by
  10.     the Free Software Foundation version 1
  11.  
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. /* file: coder 1 */
  22. #include "gg1.h"
  23. #include "gg2.h"
  24. int             nraffixes,
  25.                 alt_nr = 0,
  26.                 nr_of_mems = 0,
  27.                 no_inherited_afx,
  28.                 highest_tempory,
  29.                 memo_alt,
  30.                 mems_lifted,
  31.                 lift_count = 0,
  32.                 total_nr_of_mems = 0;
  33.  
  34. char           *rrrt = "";
  35.  
  36. code()
  37. {
  38.                 alt_nr = 0,
  39.                 nr_of_mems = 0,
  40.                 lift_count = 0,
  41.                 total_nr_of_mems = 0;
  42.   if (output != stdout) {
  43.     if (syntax_flag &&!separate_comp_flag) {
  44.        outputfile[strlen(outputfile)-3] = '.'; 
  45.        outputfile[strlen(outputfile)-2] = 'c'; 
  46.        outputfile[strlen(outputfile)-1] = '\0'; 
  47.     }
  48.     output = fopen(outputfile, "w");
  49.   }
  50.   if (output == NULL) {
  51.     fprintf(stderr, "glammar: cannot write to %s. Bye!\n",
  52.       outputfile);
  53.     exit(1);
  54.   }
  55.   fprintf(output, "\n\n/*\n * Output generated for `%s'\n */\n\n",ex_filename);
  56.  
  57. /* lattice element names */
  58.   if (max_group > 0)
  59.     conv_table(); 
  60.   else 
  61.      fprintf(output, "char **groups; /* not used */\n");
  62.   
  63. #ifdef ATARI
  64.   fprintf(output, "const long _stksize = %ldl;\n", runtime_stksize);
  65. #endif
  66.  
  67.   if (separate_comp_flag && !MARKED(root,docompile))
  68.       def_extern_meta_affixes();
  69.   else {
  70.        fprintf(output, "int backtrace = %d;\n", backtrace_mark);
  71.        def_meta_affixes();
  72.   }
  73.   if (memo_flag) {
  74.     if (nr_of_memo_alts)
  75.       fprintf(output, "#define MEMOIZE %d\n", nr_of_memo_alts+1);
  76.     else
  77.       fprintf(stderr, "no alternatives to MEMOIZE.\n");
  78.   }
  79.   SET(initmeta, deterministic);
  80.   start_code();
  81.   for (ulhs = root; ulhs != laststdpred; ulhs = BROTHER(ulhs)) {
  82.    if (!MARKED(ulhs,docompile)) {
  83.       if (memo_flag ) {
  84.      int alt;
  85.      for ( alt = SON(ulhs); alt != nil; alt = BROTHER(alt) )
  86.         if (MEMOIZE(alt))
  87.             alt_nr++;    
  88.        }
  89.    } else if (MARKED(ulhs,nondeterministic)) {
  90.        
  91.        if (MARKED(ulhs,external)) 
  92.            fprintf(output, "void u%s() {", REPR(ulhs));
  93.        else
  94.          fprintf(output, "static void U_%d() {   /* %s */ \n",
  95.                     ulhs, REPR(ulhs));
  96.     if (trace_flag)
  97.       fprintf(output, "  char *ntname = \"%s\"; int pct= parsecount;\n ", 
  98.          REPR(ulhs));
  99.     if (fprintf(output, "  register cont *rq = q;\n") == EOF) {
  100.        fprintf(stderr,"glammar: Write failed (try again later)\n");
  101.        exit(12);
  102.     }
  103.     fprintf(output, "  char *rc = c,*rip = ip;\n AFFIX raf = af;\n");
  104.     if (trace_flag)
  105.     fprintf(output, "  int ltr = level+1;\n");
  106.     if ((memo_flag) && (memo_in_alt(SON(ulhs))))
  107.          fprintf(output, "  MEMTEMPS;\n");
  108.     if (lookahead_in_alt(SON(ulhs)))
  109.       fprintf(output, "  char *lkh;\n");
  110.     if (cut_in_alt(SON(ulhs)))
  111.       fprintf(output, "  int cut_set = 0;\n");
  112.     if (ambiguous_flag)
  113.       fprintf(output, "  int aq=0,pq=parsecount;\n");
  114.     alts_code(ulhs, SON(ulhs));
  115.     if (backtrace_mark > 0)
  116.       fprintf(output, " rcount -= 1;\n");
  117.     if (trace_flag)
  118.       if (!MARKED(ulhs,external))
  119.          fprintf(output,
  120.       " (rq+1)->q = U_%d;q= rq+1;level=ltr;endtrace(pct,ntname);\n }\n", ulhs);
  121.       else 
  122.        fprintf(output,
  123.   " (rq+1)->q = u%s;q= rq+1;level=ltr;endtrace(pct,ntname);\n }\n",REPR(ulhs));
  124.     else
  125.       if (!MARKED(ulhs,external))
  126.       fprintf(output, "  (rq+1)-> q = U_%d; q = rq+1; }\n", ulhs);
  127.       else fprintf(output, "  (rq+1)-> q = u%s; q = rq+1; }\n", REPR(ulhs));
  128.     } else {
  129.        det_rule_head();
  130.        det_rule_alts(SON(ulhs));
  131.        det_rule_tail();
  132.        if ((!det_flag)  || (ulhs == root))
  133.          nondet_code();
  134.     } 
  135.    }
  136.   if (verbose_flag) {
  137.        fprintf(stderr, 
  138.  " %d predicate calls changed to function calls (on total of %d) (%.1f%%)\n",
  139.        lift_count, total_nr_of_mems, 100 * (float) lift_count
  140.       / (float) total_nr_of_mems);
  141.    }
  142.   fclose(output);
  143. }
  144.  
  145.  
  146. start_code()
  147. {
  148.  
  149.   if (!MARKED(root,external))  
  150.      fprintf(output, "static void U_%d();\n", root);
  151.   else 
  152.      fprintf(output, "void u%s();\n", REPR(root));
  153.   
  154.   if (memo_flag)
  155.       fprintf(output,"#define INPUT_MEMO_SIZE %d\n",
  156.                          runtime_input_size / (8*sizeof(int)));
  157.   
  158.  code_includes();
  159.  
  160.  
  161.   if (!separate_comp_flag) {
  162.      main_code();
  163.   } else if (MARKED(root,docompile))
  164.       main_code();
  165.  
  166.  
  167.   for (ulhs = BROTHER(root); ulhs != nil; ulhs = BROTHER(ulhs)) 
  168.          if (MARKED(ulhs,external))  {
  169.             if (MARKED(ulhs,deterministic)) 
  170.                 fprintf(output, " int d%s();\n", REPR(ulhs));
  171.             if (!det_flag) 
  172.                fprintf(output, " void u%s();\n", REPR(ulhs));
  173.           } else { 
  174.                if (MARKED(ulhs,deterministic)) 
  175.                    fprintf(output, " static int D_%d();\n", ulhs);
  176.                if (!det_flag) 
  177.                    fprintf(output, " static void U_%d();\n", ulhs);
  178.          }
  179.   if (stat_flag)
  180.       statistic_table();
  181. }
  182.  
  183.  
  184. cut_in_alt(alt)
  185.   int             alt;
  186. {
  187.   int             mem;
  188.  
  189.   for (; alt != nil; alt = BROTHER(alt))
  190.     for (mem = SON(alt); mem != nil; mem = BROTHER(mem))
  191.       if (DEF(mem) == cut)
  192.         return true;
  193.   return false;
  194. }
  195.  
  196.  
  197. cut_in_mem(mem)
  198.   int             mem;
  199. {
  200.   for (; mem != nil; mem = BROTHER(mem))
  201.     if (DEF(mem) == cut)
  202.       return true;
  203.   return false;
  204. }
  205.  
  206.  
  207. lookahead_in_alt(alt)
  208.   int             alt;
  209. {
  210.   int             mem;
  211.  
  212.   for (; alt != nil; alt = BROTHER(alt))
  213.     for (mem = SON(alt); mem != nil; mem = BROTHER(mem))
  214.       if (LKH(mem))
  215.         return true;
  216.   return false;
  217. }
  218.  
  219.  
  220.  
  221. memo_in_alt(alt)
  222.   int             alt;
  223. {
  224.   for (; alt != nil; alt = BROTHER(alt))
  225.     if (MEMOIZE(alt))
  226.       return true;
  227.   return false;
  228. }
  229.  
  230.  
  231.  
  232. lifted_mem_in_alt(alt)
  233.   int             alt;
  234. {
  235.   for (; alt != nil; alt = BROTHER(alt))
  236.     if (lift_element(SON(alt)))
  237.       return true;
  238.   return false;
  239. }
  240.  
  241.  
  242.  
  243. alts_code(rule, alt)
  244.   int             rule,
  245.                   alt;
  246. {
  247.   int             affix = (AFFIXDEF(alt)),
  248.                   c_in_mem,
  249.                   c_in_alt,
  250.                   memo_save;
  251.  
  252.   no_inherited_afx = true;
  253.   c_in_alt = cut_in_alt(SON(ulhs));
  254.   get_affixes(affix, 0);
  255. /*  save_lattice_afx();  */
  256.   if (backtrace_mark > 0)
  257.     fprintf(output, " rcount += 1;\n");
  258.   if (trace_flag)
  259.     trace_code(affix);
  260.   for (; alt != nil; alt = BROTHER(alt)) {
  261.     memo_save = DEF(alt);
  262.     set_number_of_mems(SON(alt));
  263.     c_in_mem = cut_in_mem(SON(alt));
  264.     if (memo_flag)
  265.       memo_alt = MEMOIZE(alt);
  266.     if (memo_flag && memo_alt) {
  267.       fprintf(output, "   if (SET(%d)) { \n", alt_nr);
  268.     } else
  269.       fprintf(output, "  {\n");
  270.     alt_code(alt);
  271.     fprintf(output, "  }\n");
  272.     DEF(alt) = memo_save;
  273.     if (ambiguous_flag)
  274.       fprintf(output, "  ambiguous_trace(&pq,&aq,\"%s\");\n",
  275.         REPR(rule));
  276.     fprintf(output, "   c = rc; ip = rip ; af = raf; \n");
  277.     if (trace_flag)
  278.     fprintf(output, "  level = ltr;\n");
  279.     /* restore_lattice_afx();  */
  280.     if (c_in_mem)
  281.       fprintf(output, "  if (cut_set) goto done;\n");
  282.   }
  283.   if (c_in_alt)
  284.     fprintf(output, "done:\n");
  285.   push_affixes(affix, 0);
  286.  
  287. }
  288.  
  289.  
  290. set_number_of_mems(mem)
  291.   int             mem;
  292. {
  293.   for (nr_of_mems = 0; mem != nil; mem = BROTHER(mem))
  294.     nr_of_mems += 1;
  295.   total_nr_of_mems += nr_of_mems;
  296. }
  297.  
  298.  
  299. get_affixes(affix, count)
  300.   int             affix,
  301.                   count;
  302. {
  303.   if (affix == nil) {
  304.     nraffixes = -count;
  305.     return;
  306.   }
  307.   get_affixes(BROTHER(affix), count + 1);
  308.   if (NODENAME(affix) == inherited)
  309.     no_inherited_afx = false;
  310.   if (count > 4)
  311.     fprintf(output,
  312.       "  AFFIX A_%d = (rq+%d)-> a;\n", count,
  313.       count + nraffixes + 1);
  314.   else
  315.     fprintf(output,
  316.       "  register AFFIX A_%d = (rq+%d)-> a;\n",
  317.       count, count + nraffixes + 1);
  318. }
  319.  
  320.  
  321. push_affixes(affix, count)
  322.   int             affix,
  323.                   count;
  324. {
  325.   if (affix == nil)
  326.     return;
  327.   fprintf(output, "  (rq+%d)->a = A_%d;\n", nraffixes + count
  328.     + 1, count);
  329.   push_affixes(BROTHER(affix), count + 1);
  330. }
  331.  
  332.  
  333. trace_code(affix)
  334.   int             affix;
  335. {
  336.   int             count = 0;
  337.  
  338.   fprintf(output, "   begin1_trace(ntname);\n");
  339.   for (; affix != nil; affix = BROTHER(affix)) {
  340.     if (NODENAME(affix) == inherited)
  341.       fprintf(output, "  trace_affix(A_%d);\n", count);
  342.     count += 1;
  343.   }
  344.   fprintf(output, "   begin2_trace();\n");
  345.  
  346. }
  347.  
  348.  
  349. define_all_derived_affixes(alt)
  350.   int             alt;
  351. {
  352.   int             affix,
  353.                   mem;
  354.  
  355.   for (mem = SON(alt); mem != nil; mem = BROTHER(mem))
  356.     for (affix = AFFIXTREE(mem); affix != nil; affix = BROTHER(affix)) {
  357.       int             term = SON(affix);
  358.  
  359.       if (NODENAME(affix) == derived)
  360.         if ((APPLY_BOUND_AFFIX(term)) && (!IS_LEFTDEF(term)))
  361.           fprintf(output, "  affix _%s;\n", REPR(term));
  362.       if ( (LATTICE(affix)) && (!IS_LEFTDEF(term)))
  363.           fprintf(output, "  affix _%s ;\n", REPR(term));
  364.     }
  365. }
  366.  
  367.  
  368. initialize_all_derived_affixes(alt)
  369.   int             alt;
  370. {
  371.   int             affix,
  372.                   mem;
  373.  
  374.   for (mem = SON(alt); mem != nil; mem = BROTHER(mem))
  375.     for (affix = AFFIXTREE(mem); affix != nil; affix = BROTHER(affix)) {
  376.       int             term = SON(affix);
  377.  
  378.       if (NODENAME(affix) == derived) {
  379.         if ((IS_LEFTDEF(term)) && (NODENAME(term) == affixnt)) {
  380.           if (ISNT_DONTCARE(term))   
  381.              fprintf(output, "   A_%d -> t = undefined;\n", LEFTDEF(term));
  382.         } else
  383.           fprintf(output, "   _%s.t = undefined;\n",
  384.             REPR(term));
  385.       }
  386.     }
  387. }
  388.  
  389.  
  390. nice_tree(lt, rt)
  391.   int             lt,
  392.                   rt;
  393. {
  394.   int             term;
  395.  
  396.   if (lt == rt)
  397.     return;
  398.   term = BROTHER(lt);
  399.   if (term == rt) {
  400.     if (NODENAME(lt) == affixtm) {
  401.       aCount += 1;
  402.       fprintf(output, "  T%d.t = \"%s\"; T%d.l = nil; T%d.r = nil;\n",
  403.         aCount, REPR(lt), aCount, aCount);
  404.     }
  405.     return;
  406.   } else if ((BROTHER(term) == rt) && (NODENAME(term) != affixtm)) {
  407.     aCount += 1;
  408.     if (NODENAME(lt) == affixtm) {
  409.       if (IS_LEFTDEF(term))
  410.         fprintf(output, "  T%d.t = \"%s\"; T%d.l = nil; T%d.r = A_%d;\n",
  411.           aCount, REPR(lt), aCount,
  412.           aCount, LEFTDEF(term));
  413.       else
  414.         fprintf(output, "  T%d.t = \"%s\"; T%d.l = nil; T%d.r = &_%s;\n",
  415.           aCount, REPR(lt), aCount,
  416.           aCount, REPR(term));
  417.     } else if (IS_LEFTDEF(lt)) {
  418.       if (IS_LEFTDEF(term))
  419.         fprintf(output, "  T%d.t = empty; T%d.l = A_%d; T%d.r =  A_%d;\n",
  420.           aCount, aCount, LEFTDEF(lt),
  421.           aCount, LEFTDEF(term));
  422.       else
  423.         fprintf(output, "  T%d.t = empty; T%d.l = A_%d; T%d.r = &_%s;\n",
  424.           aCount, aCount, LEFTDEF(lt),
  425.           aCount, REPR(term));
  426.     } else if (IS_LEFTDEF(term))
  427.       fprintf(output, "  T%d.t = empty; T%d.l = &_%s; T%d.r = A_%d;\n",
  428.         aCount, aCount, REPR(lt), aCount,
  429.         LEFTDEF(term));
  430.     else
  431.       fprintf(output, "  T%d.t = empty; T%d.l = &_%s; T%d.r = &_%s;\n",
  432.         aCount, aCount, REPR(lt), aCount,
  433.         REPR(term));
  434.     return;
  435.   }
  436.   if (NODENAME(lt) != affixtm) {
  437.     aCount += 1;
  438.     if (IS_LEFTDEF(lt))
  439.       fprintf(output, "  T%d.t = empty;T%d.l = A_%d;T%d.r = &T%d;\n",
  440.         aCount, aCount, LEFTDEF(lt), aCount,
  441.         aCount + 1);
  442.     else
  443.       fprintf(output, "  T%d.t = empty;T%d.l = &_%s;T%d.r = &T%d;\n",
  444.         aCount, aCount, REPR(lt), aCount,
  445.         aCount + 1);
  446.     nice_tree(BROTHER(lt), rt);
  447.   } else {
  448.     aCount += 1;
  449.     fprintf(output, "  T%d.t = \"%s\";T%d.l = nil;T%d.r = &T%d;\n",
  450.       aCount, REPR(lt), aCount, aCount, aCount +
  451.       1);
  452.     nice_tree(BROTHER(lt), rt);
  453.   }
  454. }
  455.  
  456.  
  457. nice_lift_tree(lt, rt)
  458.   int             lt,
  459.                   rt;
  460. {
  461.   int             term;
  462.  
  463.   if (lt == rt)
  464.     return;
  465.   term = BROTHER(lt);
  466.   if (term == rt) {
  467.     if (NODENAME(lt) == affixtm) {
  468.       aCount += 1;
  469.       fprintf(output, "T%d.t = \"%s\",T%d.l = nil,T%d.r = nil,",
  470.         aCount, REPR(lt), aCount, aCount);
  471.     }
  472.     return;
  473.   } else if ((BROTHER(term) == rt) && (NODENAME(term) != affixtm)) {
  474.     aCount += 1;
  475.     if (NODENAME(lt) == affixtm) {
  476.       if (IS_LEFTDEF(term))
  477.         fprintf(output, "T%d.t = \"%s\",T%d.l = nil,T%d.r = A_%d,",
  478.           aCount, REPR(lt), aCount,
  479.           aCount, LEFTDEF(term));
  480.       else
  481.         fprintf(output, "T%d.t = \"%s\",T%d.l = nil,T%d.r = &_%s,",
  482.           aCount, REPR(lt), aCount,
  483.           aCount, REPR(term));
  484.     } else if (IS_LEFTDEF(lt)) {
  485.       if (IS_LEFTDEF(term))
  486.         fprintf(output, "T%d.t = empty,T%d.l = A_%d,T%d.r = A_%d,",
  487.           aCount, aCount, LEFTDEF(lt),
  488.           aCount, LEFTDEF(term));
  489.       else
  490.         fprintf(output, "T%d.t = empty,T%d.l = A_%d,T%d.r = &_%s,",
  491.           aCount, aCount, LEFTDEF(lt),
  492.           aCount, REPR(term));
  493.     } else if (IS_LEFTDEF(term))
  494.       fprintf(output, "T%d.t = empty,T%d.l = &_%s,T%d.r = A_%d,",
  495.         aCount, aCount, REPR(lt), aCount,
  496.         LEFTDEF(term));
  497.     else
  498.       fprintf(output, "T%d.t = empty,T%d.l = &_%s,T%d.r = &_%s,",
  499.         aCount, aCount, REPR(lt), aCount,
  500.         REPR(term));
  501.     return;
  502.   }
  503.   if (NODENAME(lt) != affixtm) {
  504.     aCount += 1;
  505.     if (IS_LEFTDEF(lt))
  506.       fprintf(output, "T%d.t = empty,T%d.l = A_%d,T%d.r = &T%d,",
  507.         aCount, aCount, LEFTDEF(lt), aCount,
  508.         aCount + 1);
  509.     else
  510.       fprintf(output, "T%d.t = empty,T%d.l = &_%s,T%d.r = &T%d,",
  511.         aCount, aCount, REPR(lt), aCount,
  512.         aCount + 1);
  513.     nice_lift_tree(BROTHER(lt), rt);
  514.   } else {
  515.     aCount += 1;
  516.     fprintf(output, "T%d.t = \"%s\",T%d.l = nil,T%d.r = &T%d,",
  517.       aCount, REPR(lt), aCount, aCount, aCount +
  518.       1);
  519.     nice_lift_tree(BROTHER(lt), rt);
  520.   }
  521. }
  522.  
  523.  
  524. affix_code(mem)
  525.   int             mem;
  526. {
  527.   int             affix;
  528.  
  529.   for (affix = AFFIXTREE(mem); affix != nil; affix = BROTHER(affix)) {
  530.     int             term = SON(affix);
  531.  
  532.     if (NODENAME(affix) == inherited) {
  533.       if (BROTHER(term) != nil) {
  534.         int             this_a_count = aCount + 1;
  535.  
  536.         nice_tree(term, nil);
  537.         fprintf(output, "  (rq+%d)->a = &T%d;\n",
  538.           qCount + 1, this_a_count);
  539.       } else if (NODENAME(term) == affixtm) {
  540.         aCount += 1;
  541.         fprintf(output, "  T%d.t = \"%s\"; T%d.l = nil; T%d.r = nil;\n",
  542.           aCount, REPR(term),
  543.           aCount, aCount);
  544.         fprintf(output, "  (rq+%d)->a = &T%d;\n",
  545.           qCount + 1, aCount);
  546.       } else if (IS_LEFTDEF(term))
  547.         fprintf(output, "  (rq+%d)->a = A_%d;\n",
  548.           qCount + 1, LEFTDEF(term));
  549.       else
  550.         fprintf(output, "  (rq+%d)->a = &_%s;\n",
  551.           qCount + 1, REPR(term));
  552.     } else {
  553.       if (IS_LEFTDEF(term))
  554.         fprintf(output, "  (rq+%d)->a = A_%d;\n",
  555.           qCount + 1, LEFTDEF(term));
  556.       else
  557.         fprintf(output, "  (rq+%d)->a = &_%s;\n",
  558.           qCount + 1, REPR(term));
  559.     }
  560.     qCount += 1;
  561.   }
  562. }
  563.  
  564.  
  565. code_lifted_affixes(affix)
  566.   int             affix;
  567. {
  568.   fprintf(output, "(");
  569.   for (; affix != nil; affix = BROTHER(affix)) {
  570.     int             term = SON(affix);
  571.  
  572.     if (NODENAME(affix) == inherited) {
  573.       if (BROTHER(term) != nil) {
  574.         int             this_a_count = aCount + 1;
  575.  
  576.         fprintf(output, "(");
  577.         nice_lift_tree(term, nil);
  578.         fprintf(output, "  &T%d)", this_a_count);
  579.       } else if (NODENAME(term) == affixtm) {
  580.         aCount += 1;
  581.         fprintf(output, "  (T%d.t = \"%s\", T%d.l = nil, T%d.r = nil,&T%d)",
  582.           aCount, REPR(term),
  583.           aCount, aCount, aCount);
  584.       } else if (IS_LEFTDEF(term))
  585.         fprintf(output, "  A_%d", LEFTDEF(term));
  586.       else
  587.         fprintf(output, "  &_%s", REPR(term));
  588.     } else {
  589.       if (IS_LEFTDEF(term))
  590.         fprintf(output, "  A_%d", LEFTDEF(term));
  591.       else
  592.         fprintf(output, "  &_%s", REPR(term));
  593.     }
  594.     if (BROTHER(affix) != nil)
  595.       fprintf(output, ",");
  596.   }
  597.   fprintf(output, ")");
  598. }
  599.  
  600.  
  601. result_code(alt)
  602.   int             alt;
  603. {
  604.   int             affix,
  605.                   count = 0;
  606.  
  607.   for (affix = AFFIXDEF(alt); affix != nil; affix = BROTHER(affix)) {
  608.     if (NODENAME(affix) == derived) {
  609.       int             term = SON(affix);
  610.  
  611.       if (BROTHER(term) == nil) {
  612.         if (NODENAME(term) == affixtm)
  613.           fprintf(output,
  614.             "  A_%d -> t = \"%s\"; A_%d -> l = nil; A_%d -> r = nil;\n"
  615.             ,count, REPR(term), count, count);
  616.         else if (IS_LEFTDEF(term))
  617.           fprintf(output, "MAKE(A_%d,A_%d);\n ", count, LEFTDEF(term));
  618.         else if (FREE_AFFIX(term)) {
  619.           fprintf(output, "  A_%d -> t = _%s.t;", count, REPR(term));
  620.           fprintf(output, "A_%d -> r = nil;", count);
  621.           fprintf(output, "A_%d -> l = nil;\n", count);
  622.         }
  623.       } else {
  624.         int          this_a_count = aCount + 1, bterm = BROTHER(term);
  625.  
  626.         if (BROTHER(bterm) == nil) {
  627.           if ((NODENAME(term) == affixtm) && (NODENAME(bterm) == affixtm)) {
  628.             aCount += 1;
  629.             fprintf(output, "  T%d.t = \"%s\";", this_a_count, REPR(bterm));
  630.             fprintf(output, "T%d.l = nil;", this_a_count);
  631.             fprintf(output, "T%d.r = nil;\n", this_a_count);
  632.             fprintf(output, "  A_%d -> t = \"%s\";", count, REPR(term));
  633.             fprintf(output, "A_%d -> r = &T%d;", count, this_a_count);
  634.             fprintf(output, "A_%d -> l = nil;", count);
  635.           } else if ((NODENAME(term) != affixtm) &&
  636.                                (NODENAME(bterm) == affixtm)) {
  637.             aCount += 1;
  638.             fprintf(output, "  T%d.t = \"%s\";", this_a_count, REPR(bterm));
  639.             fprintf(output, "T%d.l = nil;", this_a_count);
  640.             fprintf(output, "T%d.r = nil;\n", this_a_count);
  641.             if (IS_LEFTDEF(term))
  642.               fprintf(output, "  A_%d -> l = A_%d;", count, LEFTDEF(term));
  643.             else
  644.               fprintf(output, "  A_%d -> l = &_%s;", count, REPR(term));
  645.             fprintf(output, "A_%d -> r = &T%d;", count, this_a_count);
  646.             fprintf(output, "A_%d -> t = empty;\n", count);
  647.           } else if ((NODENAME(term) == affixtm) &&
  648.                       (NODENAME(bterm) != affixtm)) {
  649.             fprintf(output, "  A_%d -> t = \"%s\";", count, REPR(term));
  650.             if (IS_LEFTDEF(bterm))
  651.               fprintf(output, "A_%d -> r = A_%d;", count, LEFTDEF(bterm));
  652.             else
  653.               fprintf(output, "A_%d -> r = &_%s;", count, REPR(bterm));
  654.             fprintf(output, "A_%d -> l = nil;\n", count);
  655.           } else {
  656.             fprintf(output, "  A_%d -> t = empty;", count);
  657.             if (IS_LEFTDEF(term))
  658.               fprintf(output, "A_%d -> l = A_%d;", count, LEFTDEF(term));
  659.             else
  660.               fprintf(output, "A_%d -> l = &_%s;", count, REPR(term));
  661.             if (IS_LEFTDEF(bterm))
  662.               fprintf(output, "A_%d -> r = A_%d;\n", count, LEFTDEF(bterm));
  663.             else
  664.               fprintf(output, "A_%d -> r = &_%s;\n", count, REPR(bterm));
  665.           }
  666.         } else if (NODENAME(term) != affixtm) {
  667.           nice_tree(bterm, nil);
  668.           fprintf(output, "  A_%d -> t = empty;", count);
  669.           fprintf(output, "A_%d -> r = &T%d;", count, this_a_count);
  670.           if (IS_LEFTDEF(term))
  671.             fprintf(output, "A_%d -> l = A_%d;\n", count, LEFTDEF(term));
  672.           else
  673.             fprintf(output, "A_%d -> l = &_%s;\n", count, REPR(term));
  674.         } else {
  675.           nice_tree(bterm, nil);
  676.           fprintf(output, "  A_%d -> t = \"%s\";", count, REPR(term));
  677.           fprintf(output, "A_%d -> r = &T%d;", count, this_a_count);
  678.           fprintf(output, "A_%d -> l = nil;\n", count);
  679.         }
  680.       }
  681.     } else if (LATTICE(affix)) 
  682.          if (NODENAME(SON(affix)) == affixtm) {
  683.           int term = SON(affix);
  684.           fprintf(output," A_%d ->t = (char *) 0X%x;\n",count,
  685.               NODENAME(LATTICE_DEF(term)));
  686.            
  687.     }
  688.     count += 1;
  689.   }
  690. }
  691.  
  692. code_qstack_check(mem)
  693. int mem; 
  694. {
  695.    int afx,q_top = qCount;
  696.  
  697.    for (; mem != nil ; mem = BROTHER(mem))
  698.      if (!lift_element(mem)) break;
  699.  
  700.    for (; mem != nil ; mem = BROTHER(mem))
  701.     if (STRING(mem)) q_top += 1;
  702.     else if (TERMINAL(mem)) q_top +=2;
  703.     else  {
  704.       for (afx = AFFIXTREE(mem) ; afx != nil; afx = BROTHER(afx))
  705.            q_top +=1;
  706.        q_top +=1;
  707.     }
  708.    if (q_top >0)
  709.    fprintf (output, " if (q+%d > q_top) need_more_qstack();\n", q_top);
  710. }
  711.  
  712. alt_code(alt)
  713.   int             alt;
  714. {
  715.   int             mem;
  716.  
  717.   qCount = nraffixes;
  718.   aCount = 0;
  719.   alt_intermediate_defs(alt);
  720.   aCount = 0;
  721.   define_all_derived_affixes(alt);
  722.   initialize_all_derived_affixes(alt);
  723.   code_qstack_check(SON(alt));
  724.   lift_code(alt);
  725.   mem = SON(alt);
  726.   result_code(alt);
  727.   if (mem == nil)
  728.     fprintf(output, "  q = rq+%d;(*(rq+%d)->q)();\n", qCount - 1, qCount);
  729.   else if (BROTHER(mem) == nil) {
  730. /*
  731.     if ((memo_flag) && (memo_alt))
  732.       fprintf(output, "   (rq+%d) -> q = uskip_;\n", qCount);
  733. */
  734.     if (LKH(mem)) {
  735.       lkh_epiloque();
  736.       fprintf(output, "  lkh = ip;\n");
  737.     }
  738.     if (TERMINAL(mem)) {
  739.       if (backtrace_mark > 0)
  740.         fprintf(output, "  (rq+%d)->a = A_0;\n", ++qCount);
  741.       affix_code(mem);
  742.       code_first_terminal(mem);
  743.       qCount += 2;
  744.     } else if (!MARKED(DEF(mem),external)) {
  745.       affix_code(mem);
  746.       fprintf(output, "  q = rq+%d;U_%d();\n", qCount, DEF(mem));
  747.       qCount += 1;
  748.     } else {
  749.       affix_code(mem);
  750.       if (DEF(mem) == cut)
  751.         fprintf(output, "   (rq+%d) -> i = &cut_set;\n", ++qCount);
  752.       fprintf(output, "  q = rq+%d; u%s();\n", qCount, REPR(mem));
  753.       qCount += 1;
  754.     }
  755.   } else {
  756.     mems_code(alt, BROTHER(mem));
  757.     if (LKH(mem)) {
  758.       lkh_epiloque();
  759.       fprintf(output, "  lkh = ip;\n");
  760.     }
  761.     if (TERMINAL(mem)) {
  762.       if (backtrace_mark > 0)
  763.         fprintf(output, "  (rq+%d)->a = A_0;\n", ++qCount);
  764.       affix_code(mem);
  765.       code_first_terminal(mem);
  766.       qCount += 2;
  767.     } else if (!MARKED(DEF(mem),external)) {
  768.       affix_code(mem);
  769.       fprintf(output, "  q = rq+%d;U_%d();\n", qCount, DEF(mem));
  770.       qCount += 1;
  771.     } else {
  772.       affix_code(mem);
  773.       if (DEF(mem) == cut)
  774.         fprintf(output, "   (rq+%d) -> i = &cut_set;\n", ++qCount);
  775.       if (DEF(mem) == skip) {
  776.           fprintf(output, "  /* here comes that skip */\n");
  777.            DEF(alt) = qCount;
  778.       }
  779.       fprintf(output, "  q = rq+%d;u%s();\n", qCount , REPR(mem));
  780.       qCount += 1;
  781.     }
  782.   }
  783.   if (memo_flag && memo_alt) {
  784.     fprintf(output,
  785.       "  rq = q - %d;\n   if ((rq+ %d)->q == uskip_) { CLEAR(%d); rq -=1;}\n",
  786.       qCount-1,DEF(alt) , alt_nr++);
  787.   } else if (memo_flag)
  788.     fprintf(output, "  rq = q - %d; \n", qCount);
  789.    if (mems_lifted)
  790.          fprintf(output, "   }\n");
  791. }
  792.  
  793.  
  794. lift_code(alt)
  795. int             alt;
  796. {
  797.    int             mem = SON(alt);
  798.  
  799.    mems_lifted = false;
  800.    if ((mem == nil) || (!lift_element(mem)))
  801.       return;
  802.    mems_lifted = true;
  803.    for(mem = SON(alt);(mem != nil)&&(lift_element(mem)); mem = BROTHER(mem)) {
  804.       lift_count += 1;
  805.       if (LKH(mem))
  806.             fprintf(output, "   if (lkh = ip)\n");
  807.       if (TERMINAL(mem))
  808.          code_lifted_terminal(mem, AFFIXTREE(mem));
  809.       else {
  810.          if (DEF(mem) == cut)
  811.             fprintf(output, "   if (cut_set = 1)\n");
  812.          else if (!MARKED(DEF(mem),external)) {
  813.             fprintf(output, "   if ( D_%d", DEF(mem));
  814.             code_lifted_affixes(AFFIXTREE(mem));
  815.             fprintf(output, ")\n");
  816.          }
  817.          else {
  818.             fprintf(output, "   if ( d%s", REPR(mem));
  819.             code_lifted_affixes(AFFIXTREE(mem));
  820.             fprintf(output, ")\n");
  821.          }
  822.       }
  823.       if (LKH(mem))
  824.             fprintf(output, "   if (ip = lkh)\n");
  825.    }
  826.    SON(alt) = mem;
  827.    fprintf(output, "   {", REPR(mem));
  828. }
  829.  
  830.  
  831. mems_code(alt, mem)
  832.   int             alt,
  833.                   mem;
  834. {
  835.   if (mem != nil) {
  836.  
  837.     mems_code(alt, BROTHER(mem));
  838.     if (LKH(mem))
  839.       lkh_epiloque();
  840.  
  841.     if (TERMINAL(mem)) {
  842.       if (backtrace_mark > 0)
  843.         fprintf(output, "  (rq+%d)->a = A_0;\n",
  844.           ++qCount);
  845.       affix_code(mem);
  846.       code_terminal(mem);
  847.       qCount += 2;
  848.     } else if (!MARKED(DEF(mem),external)) {
  849.       affix_code(mem);
  850.       fprintf(output, "  (rq+%d)->q = U_%d;\n", ++qCount, DEF(mem));
  851.     } else {
  852.       affix_code(mem);
  853.       if (DEF(mem) == skip) {
  854.           fprintf(output, "  /* here comes that skip */\n");
  855.            DEF(alt) = qCount;
  856.       }
  857.       if (DEF(mem) == cut)
  858.         fprintf(output, "   (rq+%d) -> i = &cut_set;\n", ++qCount);
  859.       fprintf(output, "  (rq+%d)->q = u%s;\n", ++qCount, REPR(mem));
  860.     }
  861.     if (LKH(mem))
  862.       lkh_proloque();
  863.   }
  864. }
  865.  
  866.  
  867. lkh_epiloque()
  868. {
  869.   fprintf(output, "  (rq+%d)->l = &lkh;\n", ++qCount);
  870.   fprintf(output, "  (rq+%d)->q = lkh_epiloque;\n", ++qCount);
  871. }
  872.  
  873.  
  874. lkh_proloque()
  875. {
  876.   fprintf(output, "  (rq+%d)->l = &lkh;\n", ++qCount);
  877.   fprintf(output, "  (rq+%d)->q = lkh_proloque;\n", ++qCount);
  878. }
  879.  
  880.  
  881. code_first_terminal(termi)
  882.   int             termi;
  883. {
  884.   if (STRING(termi))
  885.     fprintf(output, "  (rq+%d)->s= \"%s\"; q = rq +%d;%suterminal_();\n"
  886.       ,qCount + 1, REPR(termi), qCount + 1, rrrt);
  887.   else if (COMPLEMENT(termi)) {
  888.     if (EXCLAMATIONSTARCHOICE(termi))
  889.       fprintf(output,
  890.         "  (rq+%d)->s =\"%s\";q = rq +%d;%sux_star_ex_choice();\n",
  891.         qCount + 1, REPR(termi),
  892.         qCount + 1, rrrt);
  893.     else if (EXCLAMATIONPLUSCHOICE(termi))
  894.       fprintf(output,
  895.         "  (rq+%d)->s =\"%s\";q = rq +%d;%sux_plus_ex_choice();\n",
  896.             qCount + 1, REPR(termi), qCount + 1, rrrt);
  897.     else
  898.       fprintf(output,
  899.         "  (rq+%d)->s =\"%s\";q = rq +%d;%suex_choice();\n",
  900.             qCount + 1, REPR(termi), qCount + 1, rrrt);
  901.   } else if (EXCLAMATIONSTARCHOICE(termi))
  902.     fprintf(output,
  903.       "  (rq+%d)->s =\"%s\";q = rq +%d;%sux_star_choice();\n",
  904.       qCount + 1, REPR(termi), qCount + 1, rrrt);
  905.   else if (EXCLAMATIONPLUSCHOICE(termi))
  906.     fprintf(output,
  907.       "  (rq+%d)->s =\"%s\";q = rq +%d;%sux_plus_choice();\n",
  908.       qCount + 1, REPR(termi), qCount + 1, rrrt);
  909.   else
  910.     fprintf(output, "  (rq+%d)->s =\"%s\";q = rq +%d;%suchoice_();\n",
  911.       qCount + 1, REPR(termi), qCount + 1, rrrt);
  912. }
  913.  
  914.  
  915. code_terminal(termi)
  916.   int             termi;
  917. {
  918.   if (STRING(termi))
  919.     fprintf(output, "  (rq+%d)->s = \"%s\";(rq+%d)->q = %suterminal_;\n",
  920.       qCount + 1, REPR(termi), qCount + 2, rrrt);
  921.   else if (COMPLEMENT(termi)) {
  922.     if (EXCLAMATIONSTARCHOICE(termi))
  923.       fprintf(output,
  924.         "  (rq+%d)->s = \"%s\";(rq+%d)->q = %sux_star_ex_choice;\n",
  925.         qCount + 1, REPR(termi), qCount
  926.         + 2, rrrt);
  927.     else if (EXCLAMATIONPLUSCHOICE(termi))
  928.       fprintf(output,
  929.         "  (rq+%d)->s = \"%s\";(rq+%d)->q = %sux_plus_ex_choice;\n",
  930.         qCount + 1, REPR(termi), qCount
  931.         + 2, rrrt);
  932.     else
  933.       fprintf(output,
  934.         "  (rq+%d)->s = \"%s\";(rq+%d)->q = %suex_choice;\n",
  935.             qCount + 1, REPR(termi), qCount + 2, rrrt);
  936.   } else if (EXCLAMATIONSTARCHOICE(termi))
  937.     fprintf(output,
  938.      "  (rq+%d)->s = \"%s\";(rq+%d)->q = %sux_star_choice;\n",
  939.       qCount + 1, REPR(termi), qCount + 2, rrrt);
  940.   else if (EXCLAMATIONPLUSCHOICE(termi))
  941.     fprintf(output,
  942.      "  (rq+%d)->s = \"%s\";(rq+%d)->q = %sux_plus_choice;\n",
  943.       qCount + 1, REPR(termi), qCount + 2, rrrt);
  944.   else
  945.     fprintf(output, "  (rq+%d)->s = \"%s\";(rq+%d)->q = uchoice_;\n",
  946.       qCount + 1, REPR(termi), qCount + 2, rrrt);
  947. }
  948.  
  949.  
  950. code_lifted_terminal(termi, afx)
  951.   int             termi,
  952.                   afx;
  953. {
  954.   int             trm;
  955.  
  956.   if (STRING(termi)) {
  957.     fprintf(output, "  if (dterminal_(\"%s\"))\n", REPR(termi));
  958.     return;
  959.   }
  960.   trm = SON(afx);
  961.   if (IS_LEFTDEF(trm)) {
  962.     if (COMPLEMENT(termi)) {
  963.       if (EXCLAMATIONSTARCHOICE(termi))
  964.         fprintf(output, "  if ( dx_star_ex_choice(\"%s\",A_%d))\n",
  965.           REPR(termi), LEFTDEF(trm));
  966.       else if (EXCLAMATIONPLUSCHOICE(termi))
  967.         fprintf(output, "  if (dx_plus_ex_choice(\"%s\",A_%d))\n",
  968.           REPR(termi), LEFTDEF(trm));
  969.       else
  970.         fprintf(output, "  if (dex_choice(\"%s\",A_%d))\n",
  971.           REPR(termi), LEFTDEF(trm));
  972.     } else if (EXCLAMATIONSTARCHOICE(termi))
  973.       fprintf(output, "  if (dx_star_choice(\"%s\",A_%d))\n",
  974.         REPR(termi), LEFTDEF(trm));
  975.     else if (EXCLAMATIONPLUSCHOICE(termi))
  976.       fprintf(output, "  if (dx_plus_choice(\"%s\",A_%d))\n",
  977.         REPR(termi), LEFTDEF(trm));
  978.     else
  979.       fprintf(output, "  if (dchoice_(\"%s\",A_%d))\n",
  980.         REPR(termi), LEFTDEF(trm));
  981.   } else {
  982.     if (COMPLEMENT(termi)) {
  983.       if (EXCLAMATIONSTARCHOICE(termi))
  984.         fprintf(output, "  if (dx_star_ex_choice(\"%s\",&_%s))\n",
  985.           REPR(termi), REPR(trm));
  986.       else if (EXCLAMATIONPLUSCHOICE(termi))
  987.         fprintf(output, "  if (dx_plus_ex_choice(\"%s\",&_%s))\n",
  988.           REPR(termi), REPR(trm));
  989.       else
  990.         fprintf(output, "  if (dex_choice(\"%s\",&_%s))\n",
  991.           REPR(termi), REPR(trm));
  992.     } else if (EXCLAMATIONSTARCHOICE(termi))
  993.       fprintf(output, "  if (dx_star_choice(\"%s\",&_%s))\n",
  994.         REPR(termi), REPR(trm));
  995.     else if (EXCLAMATIONPLUSCHOICE(termi))
  996.       fprintf(output, "  if (dx_plus_choice(\"%s\",&_%s))\n",
  997.         REPR(termi), REPR(trm));
  998.     else
  999.       fprintf(output, "  if (dchoice_(\"%s\",&_%s))\n",
  1000.         REPR(termi), REPR(trm));
  1001.   }
  1002. }
  1003.  
  1004.  
  1005. count_intermediate_defs_in_tree(lt, rt)
  1006.   int             lt,
  1007.                   rt;
  1008. {
  1009.   int             term;
  1010.  
  1011.   if (lt == rt)
  1012.     return;
  1013.   term = BROTHER(lt);
  1014.   if (term == rt) {
  1015.     if (NODENAME(lt) == affixtm)
  1016.       aCount += 1;
  1017.     return;
  1018.   } else if ((BROTHER(term) == rt) && (NODENAME(term) != affixtm)) {
  1019.     aCount += 1;
  1020.     return;
  1021.   }
  1022.   if (NODENAME(lt) != affixtm) {
  1023.     aCount += 1;
  1024.     highest_tempory = aCount + 1;
  1025.     count_intermediate_defs_in_tree(BROTHER(lt), rt);
  1026.   } else {
  1027.     aCount += 1;
  1028.     highest_tempory = aCount + 1;
  1029.     count_intermediate_defs_in_tree(BROTHER(lt), rt);
  1030.   }
  1031. }
  1032.  
  1033.  
  1034. affix_intermediate_defs(mem)
  1035.   int             mem;
  1036. {
  1037.   int             affix;
  1038.  
  1039.   for (affix = AFFIXTREE(mem); affix != nil; affix = BROTHER(affix)) {
  1040.     int             term = SON(affix);
  1041.  
  1042.     if (NODENAME(affix) == inherited) {
  1043.       if (BROTHER(term) != nil)
  1044.         count_intermediate_defs_in_tree(term,
  1045.                 nil);
  1046.       else if (NODENAME(term) == affixtm)
  1047.         aCount += 1;
  1048.     }
  1049.   }
  1050. }
  1051.  
  1052.  
  1053. result_intermediate_defs(alt)
  1054.   int             alt;
  1055. {
  1056.   int             affix;
  1057.  
  1058.   for (affix = AFFIXDEF(alt); affix != nil; affix = BROTHER(affix)) {
  1059.     if (NODENAME(affix) == derived) {
  1060.       int             term = SON(affix),
  1061.                       bterm = BROTHER(term);
  1062.  
  1063.       if (bterm == nil);
  1064.       else if (BROTHER(bterm) == nil) {
  1065.         if ((NODENAME(term) == affixtm) && (NODENAME(bterm) ==
  1066.                 affixtm))
  1067.           aCount += 1;
  1068.         else if ((NODENAME(term) != affixtm) &&
  1069.               (NODENAME(bterm) == affixtm))
  1070.           aCount += 1;
  1071.       } else
  1072.         count_intermediate_defs_in_tree(bterm,
  1073.                 nil);
  1074.     }
  1075.   }
  1076. }
  1077.  
  1078.  
  1079. alt_intermediate_defs(alt)
  1080.   int             alt;
  1081.  
  1082. {
  1083.   int             mem = SON(alt),
  1084.                   count;
  1085.  
  1086.   aCount = 0;
  1087.   highest_tempory = 0;
  1088.   result_intermediate_defs(alt);
  1089.   if (mem == nil);
  1090.   else if (BROTHER(mem) == nil)
  1091.     affix_intermediate_defs(mem);
  1092.   else {
  1093.     mems_intermediate_defs(BROTHER(mem));
  1094.     affix_intermediate_defs(mem);
  1095.   }
  1096.   if (highest_tempory > aCount)
  1097.     aCount = highest_tempory;
  1098.   if (aCount == 0);
  1099.   else if (aCount == 1)
  1100.     fprintf(output, "   affix T1;\n");
  1101.   else {
  1102.     fprintf(output, "   affix T1");
  1103.     for (count = 2; count != aCount + 1; count++)
  1104.       fprintf(output, ",T%d", count);
  1105.     fprintf(output, ";\n");
  1106.   }
  1107. }
  1108.  
  1109.  
  1110. mems_intermediate_defs(mem)
  1111.   int             mem;
  1112. {
  1113.   if (mem != nil) {
  1114.     mems_intermediate_defs(BROTHER(mem));
  1115.     affix_intermediate_defs(mem);
  1116.   }
  1117. }
  1118.  
  1119.  
  1120. def_extern_meta_affixes()
  1121. {
  1122.   int             mrule;
  1123.   fprintf(output, 
  1124. "typedef struct affix{char *t; struct affix *l; struct affix *r;} affix,*AFFIX ;\n");
  1125.   for (mrule = lastmetarule; mrule != nil; mrule = BROTHER(mrule)) 
  1126.     fprintf(output, "   extern affix _%s;\n", REPR(mrule));
  1127. }
  1128.  
  1129. def_meta_affixes()
  1130. {
  1131.   int             mrule,prev=lastmetarule;
  1132.  
  1133.   fprintf(output, 
  1134. "typedef struct affix{char *t; struct affix *l; struct affix *r;} affix,*AFFIX ;\n");
  1135.   for (mrule = lastmetarule; mrule != nil; mrule = BROTHER(mrule)) {
  1136.     int                this;
  1137.     prev = mrule;
  1138.     if ((!separate_comp_flag) && (mrule > laststdmetarule))
  1139.        fprintf(output, "  static ");
  1140.     if  (NODENAME (mrule) == meta_prod_rule) 
  1141.     /* && (NODENAME(SON(mrule)) == affixtm)) */
  1142.     fprintf(output, " affix _%s = {\"%s\",0,0};\n", REPR(mrule),REPR(SON(mrule)));
  1143.     else fprintf(output, " affix _%s = {\"!@!\",0,0};\n", REPR(mrule));
  1144.   }
  1145.   fprintf(output, "AFFIX first_meta = &_%s;\n",REPR(lastmetarule));
  1146.   fprintf(output, "AFFIX last_meta = &_%s;\n",REPR(prev));
  1147. }
  1148.  
  1149. lift_element(mem)
  1150.   int             mem;
  1151.   if (mem == nil)
  1152.     return false;
  1153.   return ( (TERMINAL(mem)) || (MARKED (DEF(mem), deterministic)) ); 
  1154. }
  1155.  
  1156.  
  1157. main_code() {
  1158.       fprintf(output,"\n\
  1159. \n\
  1160. main (arg_count,arguments)\n\
  1161. int arg_count;\n\
  1162. char **arguments;\n\
  1163. {\n\
  1164.   affix r,e;\n\
  1165.   fla.t = fast_list_acces;\n\
  1166.   e.t = undefined;\n\
  1167.   r.t = e.t;\n\
  1168.   readinput(arg_count,arguments);\n\
  1169.   cstore  = input + nrofchars+10;\n\
  1170.   c = cstore; \n\
  1171.   ct = cstore;\n\
  1172.   q = q_stack;\n\
  1173.   af = affix_heap; \n\
  1174.   dInit_One_Star();\n\
  1175.   q -> a =  &r;\n\
  1176.   (++q) -> q = found; \n\
  1177.   mip = ip;\n\
  1178.   argc = arg_count; arg_v = arguments;\n\
  1179.   parsecount=0;\n");
  1180.  
  1181.    if (memo_flag && nr_of_memo_alts) {
  1182.       fprintf(output,"\n\
  1183. {       int i,j;\n\
  1184.           for (i=0; i< MEMOIZE; i+=1) \n\
  1185.                   for (j=0; j<INPUT_MEMO_SIZE; )\n\
  1186.                          memo_table[i] [j++] = -1;\n\
  1187. }\n");
  1188.    }
  1189.  
  1190.  
  1191.  
  1192.   if (backtrace_mark > 0)
  1193.     fprintf(output,
  1194.     "  e.t = \" %s\";e.r = nil; e.l = nil;(++q) -> a = &e;\n",
  1195.       REPR(root));
  1196.   fprintf(output, "  (++q) -> a = &r;\n");
  1197.   if (!MARKED(root, external))
  1198.      fprintf(output, "set_and_test_limits(1,%d);loop_line_mode(U_%d);\n", 
  1199.                      memo_flag,root);
  1200.   else 
  1201.    fprintf(output,"set_and_test_limits(1,%d);loop_line_mode(u%s);\n", 
  1202.                            memo_flag,REPR(root));
  1203.   if (stat_flag)
  1204.     fprintf(output, "print_stat();\n\n");
  1205.   if (noerrmsg_flag)
  1206.     fprintf(output, "if (parsecount == 0) exit(error_code);\n}\n");
  1207.   else
  1208.     fprintf(output, "exit(errmsg());\n}\n");
  1209.  
  1210.  
  1211. }
  1212.